package com.senseuni.common.dialog.indicator;

import android.animation.ValueAnimator;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

public abstract class BaseIndicatorController {

    private View mTarget;

    private List<ValueAnimator> mAnimationList;

    public void setTarget(View target){
        this.mTarget=target;
    }

    public View getTarget(){
        return mTarget;
    }


    public int getWidth(){
        return mTarget.getWidth();
    }

    public int getHeight(){
        return mTarget.getHeight();
    }

    public void postInvalidate(){
        mTarget.postInvalidate();
    }

    /**
     * draw indicator what ever
     * you want to draw
     * @param canvas
     * @param paint
     */
    public abstract void draw(Canvas canvas,Paint paint);

    /**
     * create animation or animations
     * ,and add to your indicator.
     */
    public abstract void createAnimation();


    protected void addAnimator(ValueAnimator animator) {
        if (mAnimationList == null) {
            mAnimationList = new ArrayList<>();
        }
        mAnimationList.add(animator);
    }

    public void cancelAnimation() {
        if (mAnimationList == null) {
            return;
        }
        for (ValueAnimator animator : mAnimationList) {
            animator.removeAllUpdateListeners();
            animator.cancel();
        }
        mAnimationList.clear();
        mAnimationList = null;
    }

}
